#include "stm32f2xx.h"
#include "stdio.h"

void int_to_char(int* p_data, char* p_adress)
{
	uint8_t* tmp = NULL;
	tmp = (uint8_t*)p_data;
	p_adress[0] = *tmp;
	p_adress[1] = *(tmp+1);
	p_adress[2] = *(tmp+2);
	p_adress[3] = *(tmp+3);
}

int32_t char_to_int32(uint8_t* p_adress)
{
	int32_t* tmp = NULL;
	int32_t data;
	tmp = (int32_t*)p_adress;
	data = *tmp;
	return data;							
} 

float char_to_float(uint8_t* p_adress)
{
	float* tmp = NULL;
	float data;
	tmp = (float*)p_adress;
	data = *tmp;
	return data;							
} 

void float_to_char(float* p_data, char* p_adress)
{
	uint8_t* tmp = NULL;
	tmp = (uint8_t*)p_data;
	p_adress[0] = *tmp;
	p_adress[1] = *(tmp+1);
	p_adress[2] = *(tmp+2);
	p_adress[3] = *(tmp+3);
}

int int_abs(int data)
{
	return data>0?data:(-data);
}

int distance(int pos1,int pos2)
{
	return int_abs(pos1-pos2);
}

void frame2data(uint8_t frame[4], uint8_t* data)
{
    *data++	= frame[0];
    *data++	= frame[1];
    *data++	= frame[2];
    *data++	= frame[3];
}
